<template>
  <div class="header_box">
    <div class="header_box_left">
      <span>{{ leftData.title }}</span>
      <span>{{ leftData.desc }}</span>
    </div>
    <div class="header_box_center">
      <div v-for="(item, index) in centerData" :key="index" :class="active == index ? 'active' : ''"
        @click="changeType(index)">{{ item }}</div>
    </div>
    <div class="header_box_right">{{ times }}</div>
  </div>
</template>
<script>

export default {
  props: {
    leftData: {
      type: Object,
      default: {}
    },
    active: {
      type: Number,
      default: 0
    },
  },
  data() {
    return {
      times: null,
      // active: 0,
      centerData: ['人资履约', '营运成本', '资产物资', '成本支付', '销售']
    }

  },
  created() {
    this.getTimes();
  },
  methods: {
    changeType(index) {
      this.active = index
      if (index == 0) {
        this.$router.push("/HRAndContract")
      } else if (index == 1) {
        this.$router.push("/costsAndPayments")
      } else if (index == 2) {
        this.$router.push("/assetsAndMaterials")
      } else if (index == 4) {
        this.$router.push("/sales")
      }

    },
    getTimes() {
      setInterval(this.getTimesInterval, 1000);
    },
    getTimesInterval() {
      let year = new Date().getFullYear(); //获取当前时间的年份
      let month = new Date().getMonth() + 1; //获取当前时间的月份
      let day = new Date().getDate(); //获取当前时间的天数
      let hours = new Date().getHours(); //获取当前时间的小时
      let minutes = new Date().getMinutes(); //获取当前时间的分数
      let seconds = new Date().getSeconds(); //获取当前时间的秒数
      //当小于 10 的是时候，在前面加 0
      if (hours < 10) {
        hours = "0" + hours;
      }
      if (minutes < 10) {
        minutes = "0" + minutes;
      }
      if (seconds < 10) {
        seconds = "0" + seconds;
      }
      //拼接格式化当前时间
      this.times = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
    },
  },
  beforeDestroy() {
    if (this.times) {
      clearInterval(this.getTimesInterval);
    }
  },

}
</script>
<style lang="scss" scoped>
.header_box {
  height: 70px;
  background: #fff;
  display: flex;
  padding: 0 28px;
  box-sizing: border-box;
  align-items: center;

  .header_box_left {
    display: flex;
    flex-direction: column;
    color: #999;
    width: 15%;

    span:nth-child(1) {
      color: #0354FA;
      font-size: 20px;
      line-height: 28px;
      font-weight: bold;
    }
  }

  .header_box_center {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    height: 100%;

    div {
      width: 134px;
      margin: 0 80px;
      text-align: center;
      line-height: 70px;
      cursor: pointer;
    }

    .active {
      line-height: 65px;
      border-top: 5px solid rgba(0, 80, 250, 1);
      font-weight: bold;
      background: linear-gradient(180deg, rgba(0, 80, 250, 0.3) 2%, rgba(80, 135, 135, 0) 100%);
    }
  }

  .header_box_right {
    font-size: 14px;
    line-height: 20px;
    color: #333;
    width: 15%;
    text-align: right;
  }
}
</style>
